﻿//------------------------------------------------------------------------------
// <copyright file="Foundation.cs" company="CommerceServer.net, Inc">
//    (c) 2012 CommerceServer.net, Inc. and its affiliates. All rights reserved.
// </copyright>
// <summary></summary>
//------------------------------------------------------------------------------ 
namespace CommerceServerContrib.CodeGeneration
{
    using CommerceServer.Foundation;
    using System;

    public class Foundation
    {
        private string channel = string.Empty;
        private string userLocale = "en-US";
        private string userUILocale = "en-US";
        private OperationServiceAgent operationService;

        public Foundation()
        {
        }

        public Foundation(string channel, string userLocale, string userUILocale)
        {
            this.channel = channel;
            this.userLocale = userLocale;
            this.userUILocale = userUILocale;
        }

        protected OperationServiceAgent OperationServiceAgent
        {
            get
            {
                if (this.operationService == null)
                {
                    this.operationService = new OperationServiceAgent();
                }

                return this.operationService;
            }
        }

        protected virtual CommerceRequestContext CreateRequestContext()
        {
            var requestContext = new CommerceRequestContext();
            requestContext.RequestId = Guid.NewGuid().ToString();
            requestContext.UserLocale = this.userLocale;
            requestContext.UserUILocale = this.userUILocale;
            requestContext.Channel = this.channel;
            return requestContext;
        }

        protected CommerceResponse InvokeFoundation(CommerceRequest request)
        {
            return this.OperationServiceAgent.ProcessRequest(this.CreateRequestContext(), request);
        }
    }
}
